package com.zmn.oms.business.impl.third;

import com.zmn.common.utils.number.NumberUtil;
import com.zmn.common.utils.string.StringUtil;
import com.zmn.oms.business.interfaces.third.ToutiaoCompanyAccountService;
import com.zmn.oms.model.entity.third.ToutiaoCompanyAccount;
import com.zmn.oms.persistence.interfaces.third.ToutiaoCompanyAccountDao;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

/**
 * 类描述：头条平台公司账号信息查询接口
 *
 * @author XieWenBing
 * @date 2020/11/25 17:00
 */
@Service
public class ToutiaoCompanyAccountServiceImpl implements ToutiaoCompanyAccountService {

    @Resource
    private ToutiaoCompanyAccountDao toutiaoCompanyAccountDao;

    /**
     * 列出所有的公司信息
     *
     * @return
     */
    @Override
    public List<ToutiaoCompanyAccount> listAllCompanyAccount() {
        return toutiaoCompanyAccountDao.listAllCompanyAccount();
    }

    /**
     * 添加头条平台公司账号信息
     *
     * @param toutiaoCompanyAccount
     */
    @Override
    public void insertCompanyAccount(ToutiaoCompanyAccount toutiaoCompanyAccount) {
        if (Objects.isNull(toutiaoCompanyAccount)) {
            return;
        }

        toutiaoCompanyAccountDao.insertCompanyAccount(toutiaoCompanyAccount);
    }

    /**
     * 删除头条平台公司账号信息
     * @param key
     */
    @Override
    public void deleteCompanyAccountByKey(String key) {
        if (StringUtil.isBlank(key)) {
            return;
        }

        toutiaoCompanyAccountDao.deleteCompanyAccountByKey(key);
    }

    /**
     * 根据渠道id查找头条公司平台信息
     *
     * @param channelId
     * @return
     */
    @Override
    public List<ToutiaoCompanyAccount> listCompanyAccountByChannelId(Integer channelId) {
        if (NumberUtil.isNullOrZero(channelId)) {
            return null;
        }

        return toutiaoCompanyAccountDao.listCompanyAccountByChannelId(channelId);
    }
}
